$(document).ready(function() {
	var role = getRole();
	var showIds = rolePrivilege[role];
	if(role == "custMem"){
		if(!isGroupUser()){
			showIds.push("_header_report_myreport_li");
		}
	}
	//如果是子用户
	if(role == "commCustMem"){
		var permission = getCookie("sub_permission");
		if(permission != undefined && permission != null && permission != "null"
				&& permission != "false" && permission != "undefined" && permission != ""){
			permission = eval('('+permission+')');
		}else{
			permission = {};
			permission.buttonTriggers = [];
			permission.tabTriggers = [];
			permission.headerTriggers = [];
		}
		showIds = showIds.concat(permission.headerTriggers);
		setSubAccountPermission(permission);
	}
	var length = allPrivilegeIds.length;
	var _allPrivilegeIds = "";
	for(var i=0;i<length;i++){
		_allPrivilegeIds = _allPrivilegeIds+"#"+allPrivilegeIds[i]+",";
	}
	$(_allPrivilegeIds).hide();
	length = showIds.length;
	var _showIds = "";
	for(var i=0;i<length;i++){
		_showIds = _showIds+"#"+showIds[i]+",";
	}
	$(_showIds).show();
	if($("#_header_info_send_his").parent().attr("class").indexOf("cur")>-1){
			$("._header2_account_manager").hide();
	}
	if($("#_header_account_manager").parent().attr("class").indexOf("cur")>-1){
		$("._header2_send_record").hide();
	}
	
	if(getCookie("mc") != '1'){
		$("#_header_send_medicine_order_li").hide();
	}
	
	setExportMenu();
});
var allPrivilegeIds = new Array(//不同角色显隐状态不同的元素id
		//储值卡登陆按钮
		"sfcardLoginHref",
		//第三方登录按钮
		"openidlogintrid",
		//top-menu
		"_header_mem_register", "_header_mem_login","mem_logout", "langSelector", "lang_sc",
		//我要寄件
		"_header_send_normal_li", "_header_send_Dnormal_li", "_header_send_batch_order_li","_header_inner_send_normal_li", 
		"_header_discount_send_normal_li","_header_discount_confirm_li",//,"_header_inner_send_staff_li"
		"_header_export_order_hkmt_li","_header_export_order_internatinal_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li", "_header_tracing_waybill_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", "_header_info_coupon_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li","_header_info_authorization_li","_header_info_sfpay_account_li", "_header_info_sfbest_li", "_header_info_otherservice_li",
		//账单报表
		"_header_reprot_li","_header_report_myreport_li","_header_report_bill_li","_header_report_groupreport_li", "_header_report_ebill_check_li",
		//menu
		"onlySC",
		//head2寄件记录
		"li_header2_order_his","li_header2_send_waybill_his","li_header2_rec_waybill_his",
		"li_header2_export_waybill","li_header2_tracing_waybill",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li","_header2_info_my_point_li","_header2_info_coupon_li",
		"_header2_info_pwd_li","_header2_info_subscription_li","_header2_info_template_li","_header2_info_authorization_li",
		"_header2_info_sfpay_account_li","_header2_info_sfbest_li", "_header2_info_otherservice_li"
);
//内地未登录
var noLoginSCMem = new Array(
		//储值卡登陆按钮
		"sfcardLoginHref",
		//第三方登录按钮
		"openidlogintrid",
		//top-menu
		"_header_mem_register", "_header_mem_login",
		//我要寄件
		"_header_send_normal_li", "_header_send_batch_order_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li", 
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", "_header_info_coupon_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li","_header_info_sfpay_account_li", "_header_info_sfbest_li", "_header_info_otherservice_li",
		//账单报表
		//menu
		"onlySC"
		//head2寄件记录
		//head2账户管理
);
//海外未登录
var noLoginaBroadMem = new Array(
		//top-menu
		"_header_mem_register", "_header_mem_login", "langSelector", 
		//我要寄件
		"_header_send_normal_li",
		//寄件记录
		 "_header_order_his_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_pwd_li","_header_info_subscription_li"
		//账单报表
		//menu
		//head2寄件记录
		//head2账户管理
);
//内地登录普通
var loginSCCommMem = new Array(
		//top-menu
		"mem_logout", 
		//我要寄件
		"_header_send_normal_li", "_header_send_batch_order_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", "_header_info_coupon_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li","_header_info_sfpay_account_li", "_header_info_sfbest_li", "_header_info_otherservice_li",
		//账单报表
		//menu
		"onlySC",
		//head2寄件记录
		"li_header2_order_his","li_header2_send_waybill_his","li_header2_rec_waybill_his",
		"li_header2_export_waybill",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li","_header2_info_my_point_li","_header2_info_coupon_li",
		"_header2_info_pwd_li","_header2_info_subscription_li","_header2_info_template_li",
		"_header2_info_sfpay_account_li","_header2_info_sfbest_li", "_header2_info_otherservice_li"
);
//海外登录普通用户
var loginaBroadCommMem = new Array(
		//top-menu
		"mem_logout", "langSelector",
		//我要寄件
		"_header_send_normal_li","_header_send_Dnormal_li",
		//寄件记录
		 "_header_order_his_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li", 
		"_header_pwd_li","_header_info_subscription_li",
		//账单报表
		//menu
		//head2寄件记录
		"li_header2_order_his",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li",
		"_header2_info_pwd_li","_header2_info_subscription_li"
);
//内部员工
var innerMem = new Array(
		//top-menu
		"mem_logout",
		//我要寄件
		"_header_inner_send_normal_li", "_header_discount_send_normal_li","_header_discount_confirm_li",//,"_header_inner_send_staff_li"
		//寄件记录
		 "_header_order_his_li", "_header_inner_discount_order_his_li", 
		//账户管理 
		"_header_info_address_li",
		//账单报表
		//menu
		"onlySC"
		//head2寄件记录
		//head2账户管理
);
//企业用户
var custMem = new Array(
		//top-menu
		"mem_logout", 
		//我要寄件
		"_header_send_batch_order_li","_header_send_medicine_order_li",
		//"_header_export_order_hkmt_li","_header_export_order_internatinal_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li", "_header_tracing_waybill_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li","_header_info_authorization_li",
		//账单报表
		"_header_reprot_li","_header_report_bill_li", "_header_report_ebill_check_li", //"_header_report_myreport_li",
		//menu
		"onlySC",
		//head2寄件记录
		"li_header2_order_his","li_header2_send_waybill_his","li_header2_rec_waybill_his",
		"li_header2_export_waybill","li_header2_tracing_waybill",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li","_header2_info_my_point_li",
		"_header2_info_pwd_li","_header2_info_subscription_li","_header2_info_template_li","_header2_info_authorization_li"
);
//集团用户
var groupCustMem = new Array(
		//top-menu
		"mem_logout", 
		//我要寄件
		"_header_send_batch_order_li","_header_send_medicine_order_li",
		//"_header_export_order_hkmt_li","_header_export_order_internatinal_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li", "_header_tracing_waybill_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li",
		//账单报表
		"_header_reprot_li","_header_report_groupreport_li", "_header_report_ebill_check_li", //"_header_report_myreport_li",
		//menu
		"onlySC",
		//head2寄件记录
		"li_header2_order_his","li_header2_send_waybill_his","li_header2_rec_waybill_his",
		"li_header2_export_waybill","li_header2_tracing_waybill",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li","_header2_info_my_point_li",
		"_header2_info_pwd_li","_header2_info_subscription_li","_header2_info_template_li"
);
//子用户
var commCustMem = new Array(
		//top-menu
		"mem_logout", 
		//我要寄件
		"_header_send_normal_li", "_header_send_batch_order_li","_header_send_medicine_order_li",
		//寄件记录
		 "_header_order_his_li","_header_send_waybill_his_li", 
		"_header_rec_waybill_his_li","_header_export_waybill_li",
		//账户管理 
		"_header_info_li", "_header_info_address_li","_header_info_my_point_li", "_header_info_coupon_li", 
		"_header_pwd_li","_header_info_subscription_li", "_header_info_template_li","_header_info_sfpay_account_li", "_header_info_sfbest_li", "_header_info_otherservice_li",
		//账单报表
		//menu
		"onlySC",
		//head2寄件记录
		"li_header2_order_his","li_header2_send_waybill_his","li_header2_rec_waybill_his",
		"li_header2_export_waybill",
		//head2账户管理
		"_header2_info_li","_header2_info_address_li","_header2_info_my_point_li","_header2_info_coupon_li",
		"_header2_info_pwd_li","_header2_info_subscription_li","_header2_info_template_li",
		"_header2_info_sfpay_account_li","_header2_info_sfbest_li", "_header2_info_otherservice_li"
);
function getRole(){
	var l = getL();//2login
	var ut = getUT();//1inner
	var ct =  getCT();//1cust
	var regionCode = getRegionCode();
	if(l==2){
		if(ut==1)return "innerMem";
		if(ct==1){
			if(isGroupUser()){
				return "groupCustMem";
			}else{
				return "custMem";
			}
		}
		if(ct==2)return regionCode=="cn"?"commCustMem":"loginaBroadCommMem";//"commCustMem";
		return regionCode=="cn"?"loginSCCommMem":"loginaBroadCommMem";
	}else{
		return regionCode=="cn"?"noLoginSCMem":"noLoginaBroadMem";
	}
}
function setExportMenu(){
	//_header_export_order_hkmt_li","_header_export_order_internatinal_li
	if(hasExportInterPre()){
		$("#_header_export_order_internatinal_li").show();
	}
	if(hasExportHKMTPre()){
		$("#_header_export_order_hkmt_li").show();
	}
}
function hasExportInterPre(){//具备出口海外权限
	return "1" == getCookie("einter");
}
function hasExportHKMTPre(){//具备出口港澳台权限
	return "1" == getCookie("ehkmt");
}
var rolePrivilege = {
		"noLoginSCMem":noLoginSCMem,	
		"noLoginaBroadMem":noLoginaBroadMem,	
		"loginSCCommMem":loginSCCommMem,	
		"loginaBroadCommMem":loginaBroadCommMem,	
		"innerMem":innerMem,	
		"custMem":custMem,
		"commCustMem":commCustMem,
		"groupCustMem":groupCustMem
	};


function setSubAccountPermission(permission){
	var noPermissionFlg = true;
	
	var buttonTriggers = permission.buttonTriggers;
	$("[id^='_btn_']").each(function(){
		noPermissionFlg = true;
		for(var i=0;i<buttonTriggers.length;i++){
			if($(this).attr("id") == buttonTriggers[i]){
				noPermissionFlg = false;
			}
		}
		if(noPermissionFlg) $(this).hide();
	});
	
	var tabTriggers = permission.tabTriggers;
	$("[id^='_tabs_']").each(function(){
		noPermissionFlg = true;
		for(var i=0;i<tabTriggers.length;i++){
			if($(this).attr("id") == tabTriggers[i]){
				noPermissionFlg = false;
			}
		}
		if(noPermissionFlg) $(this).hide();
	});
}


